{% extends base %}

{% block head %}

{% set search_action = '/fs_find' %}
{% set search_placeholder = '搜索文件' %}

{% end %}

{% block search_form %}
    <input type="text" name="path" class="hide" value="{{?path}}"/>
{% end %}

{% block body %}

{% init find_key = "" %}
{% init error = "" %}
{% init show_fs_path = True %}
{% init search_category = "fs" %}

<div class="hide error row"></div>
<div class="hide success row"></div>

<div class="grid-card">

{% if show_fs_path %}
    {% include mod_fs_path.html %}
{% end %}

{% include fs/fs_options.html %}

<div class="col-md-12 file-list">
<table class="col-md-12 no-border-table">
{% for item in filelist %}
    {# 隐藏文件 #}
    {% if item.name == "" %}
        {% set print("overflow fileItem=%s" % item) %}
        {% continue %}
    {% end %}

    {% if xconfig.FS_HIDE_FILES and (item.name[0] == "." 
            or item.name.endswith((".pyc", ".class"))) %}
        {% continue %}
    {% end %}

    <tr>
        <td class="checkboxTd"><input type="checkbox" data-path="{{item.path}}" data-name="{{item.name}}"></td>
        <td>
        {% if item.type == "dir" %}
            <img src="/static/image/folder.gif"/>
            <a href="/fs/{{item.path}}" class="fs-folder">{{item.name}}</a>
        {% else %}
            {# 默认点击按照mimetype处理 #}
            <a class="fs-file" href="/fs/{{item.path}}">{{item.name}}</a>

            {# 图片浏览器，这个要放在最后 #}
            {% if xutils.is_img_file(item.path) %}
                <div class="fs-image-div" img-src="/fs/{{item.path}}"></div>
            {% end %}

        {% end %}
        </td>
        <td class="options-td">
            {{item.size}}
        </td>
        <td class="options-td">
            <div class="float-right">
                {% if item.type != "dir" %}

                    {# 文本编辑器 #}
                    {% if xutils.is_text_file(item.path) %}
                        <a class="item-option" href="/code/edit?path={{url_escape(item.path)}}">编辑</a>
                    {% end %}

                    {% if item.ext == ".txt" %}
                        <a class="item-option" href="/tools/txtreader?path={{item.path}}&from=/fs/{{path}}">阅读</a>
                    {% end %}

                    {% if item.ext == ".db" %}
                        <a class="item-option" href="/tools/sql?path={{item.path}}&from=/fs/{{path}}">查看</a>
                    {% end %}

                    {% if item.ext in (".htm", ".html") %}
                        <a class="item-option" href="/fs/{{item.path}}">预览</a>
                    {% end %}

                    {% if item.ext.lower() in (".md", ".csv") %}
                        <a class="item-option" href="/code/wiki/{{item.path}}">预览</a>
                    {% end %}

                    {% if item.ext.lower() in (".pdf", ".mp4") %}
                        <a class="item-option" href="/tools/iframe_viewer?path={{quote(item.path)}}">预览</a>
                    {% end %}

                    <a class="item-option" href="/fs/{{item.path}}?type=blob&token={{token}}">下载</a>
                {% end %}
                <a class="item-option delete-link" data-path="{{item.path}}" href="#">删除</a>
                <a class="item-option" 
                    data-path="{{item.path}}"
                    onclick="openFileOption(this)">更多</a>
            </div>
        </td>
        
    </tr>
        
{% end %}
</table>

<input type="text" class="cmd-input" placeholder="请输入指令">
</div>
</div>

{% if error != "" %}
<div class="card">
    <pre class="error col-md-12">{{error}}</pre>
</div>
{% end %}

{% end %}

{% block aside %}
    {% include fs/mod_aside.html %}
{% end %}